import Mock from 'mockjs'
import { apiConfig } from '../api/index'
const Random = Mock.Random;

const list = (options)=>{
  // console.log('opt:',options);
  let len = Random.natural(5,10);
  let temp = [];
  for(let i =0;i<len;i++){
    let item = {
        id: i+1,
        name: Random.cname(),
        tag: Random.string('lower',3,10),
        age: Random.natural(1,100),
        email: Random.email()
    }
    temp.push(item)
  }
  return temp;
}

 let details = {
   'user':'@cname',
  'item|1-10': [
    {
      'id|+1': 0,
      'date': Random.date(),
      'img': Random.image('500x300',Random.color(),'#FFF','jpg','AAA')
    }
  ]
}

function mock(item,data){
  Mock.mock(RegExp(item.url+'.*'),item.type?item.type:'get',data);
}

mock(apiConfig.user.getList,list);
mock(apiConfig.user.getDetails,details);

